using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using LCL.LData;
using LCL.Config;

namespace LCL.Tools
{
    /// <summary>
    /// 全局变量
    /// </summary>
    public class Utility
    {
        public static IDbObject GetDbo()
        {
            IDbObject iDbObject = DBOMaker.GetDbObject(DbConfig.GetConfig());
            return iDbObject;
        }
        public static DbAccesser GetDba()
        {
            return DBOMaker.GetDbAccesser(DbConfig.GetConfig());
        }
        public static IDbScriptBuilder GetDbs()
        {
            return  DBOMaker.GetDbScript(DbConfig.GetConfig());
        }
        #region

        public static string GetClassName(string tableName, bool islower = false)
        {
            try
            {
                string[] arr = AppConfig.GetInstance().TableFormat.Split('|');
                for (int i = 0; i < arr.Length; i++)
                {
                    tableName = tableName.Replace(arr[i], "");
                }
                return islower ? tableName.ToLower() : tableName;
            }
            catch
            {
                return tableName;
            }
        }
      
        public static T GetObjTranNull<T>(object obj)
        {
            try
            {
                if (obj == null)
                {
                    return (T)System.Convert.ChangeType("", typeof(T));
                }
                else
                {
                    if (obj.GetType() == typeof(T))
                        return (T)obj;
                }

                return (T)System.Convert.ChangeType(obj, typeof(T));
            }
            catch
            {

            }
            return default(T);
        }
        #endregion

    }


}
